package study;


import java.util.Arrays;

class Solution {
    public int[] twoSum(int[] nums, int target) {
        int[] array = new int[2];
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    array[0] = i;
                    array[1] = j;
                }
            }
        }
        return  array;
    }

    public int lengthOfLongestSubstring(String s) {
        // 记录字符上一次出现的位置
        int[] last = new int[128];
        for(int i = 0; i < 128; i++) {
            last[i] = -1;
        }
        int n = s.length();

        int res = 0;
        int start = 0; // 窗口开始位置
        for(int i = 0; i < n; i++) {
            int index = s.charAt(i);
            start = Math.max(start, last[index] + 1);
            res   = Math.max(res, i - start + 1);
            last[index] = i;
        }
        return res;
    }

    public static void  main(String[] args){
        int[] num = new int[]{1,2,3,4,5,6};
        int target = 5;
        Solution solution = new Solution();
        int[] re = solution.twoSum(num,target);
        System.out.println(Arrays.toString(re));

        int a = solution.lengthOfLongestSubstring("asdfffa");
        System.out.println(a);
    }
}